package com.lovo.project.servlet.shop;

import com.lovo.project.exception.OurException;
import com.lovo.project.model.ShopDO;
import com.lovo.project.service.ShopService;
import com.lovo.project.service.impl.ShopServiceImpl;
import com.lovo.project.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UpdateShopServlet",value = "/shop/updateShop")
public class UpdateShopServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       try {
           String name = request.getParameter("shopName");
           String licenseNum = request.getParameter("shopLicenseNum");
           String licenseImg = request.getParameter("shopLicenseImg");
           String address = request.getParameter("shopAddress");
           String location = request.getParameter("shopLocation");
           String legalPerson = request.getParameter("shopLegalPerson");
           String phone = request.getParameter("shopPhone");
           String headimg = request.getParameter("shopHeadimg");
           String feature = request.getParameter("shopFeature");
           String vipgrade = request.getParameter("shopVipgrade");
           String commissionRate = request.getParameter("shopCommissionRate");
           Integer id = Integer.parseInt(request.getParameter("shopId"));
           ShopDO shop = new ShopDO();
           shop.setShopId(id);
           shop.setShopName(name);
           shop.setShopLicenseNum(licenseNum);
           shop.setShopLicenseImg(licenseImg);
           shop.setShopAddress(address);
           shop.setShopLocation(location);
           shop.setShopLegalPerson(legalPerson);
           shop.setShopPhone(phone);
           shop.setShopHeadimg(headimg);
           shop.setShopFeature(feature);
           shop.setShopVipgrade(vipgrade);
           shop.setShopCommissionRate(commissionRate);
           ShopService shopService = new ShopServiceImpl();
           shopService.update(shop);
           response.getWriter().print(ResultVO.success().toJson());
       }catch (OurException o){
           response.getWriter().print(ResultVO.fail(o.getCodeEnum()));
       }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
